import pako from "pako";

export const unzip = (b64Data) => {
  if (b64Data == null || b64Data == '') {
    return b64Data
  }
  // 将base64转为字节
  let strData   = atob(b64Data);
   // 将字节数组转为字符数组
   let charData  = strData.split('').map(function(x){return x.charCodeAt(0);});
  // 将字节数组转换为 Unit8对象的字节数组
  let binData   = new Uint8Array(charData);
  // 解压成字符串
  let data    = pako.inflate(binData,{to:'string'});
  // 解析为json
  try {
    // 返回token
    return JSON.parse(data)
  } catch (error) {
    return data
  }
}